package com.cosmoplat.xikai.business.controller;

import com.cosmoplat.xikai.business.domain.dto.alarm.AlarmQueryDTO;
import com.cosmoplat.xikai.business.domain.dto.quality.QualityHandleDTO;
import com.cosmoplat.xikai.business.domain.dto.quality.QualityQueryDTO;
import com.cosmoplat.xikai.business.domain.vo.AlarmVo;
import com.cosmoplat.xikai.business.domain.vo.ProcessingDataVo;
import com.cosmoplat.xikai.business.domain.vo.ProductQuality;
import com.cosmoplat.xikai.business.domain.vo.orderTemplate.ProductPlanTemplate;
import com.cosmoplat.xikai.business.service.QualityService;
import com.cosmoplat.xikai.common.core.controller.BaseController;
import com.cosmoplat.xikai.common.core.domain.AjaxResult;
import com.cosmoplat.xikai.common.core.page.TableDataInfo;
import com.cosmoplat.xikai.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @ClassName QualityController
 * @Description 质量控制
 * @Author wdf
 * @Date 2025/1/13
 */


@Api(tags = "质量管理", value = "质量管理")
@RestController
@Slf4j
@RequestMapping("/quality")
public class QualityController extends BaseController {


    @Autowired
    private QualityService qualityService;

    /**
     * 过程加工数据
     * @date 10:00 2025/1/13
     * @param queryDTO
     * @return com.cosmoplat.xikai.common.core.page.TableDataInfo<com.cosmoplat.xikai.business.domain.vo.ProcessingDataVo>
     **/
    @ApiOperation(value = "过程加工数据-分页查询")
    @PreAuthorize("@ss.hasPermi('business:processingData:query')")
    @GetMapping("/queryProcessingDataForPage")
    public TableDataInfo<ProcessingDataVo> queryProcessingDataForPage(QualityQueryDTO queryDTO) {
        startPage();
        List<ProcessingDataVo> list = qualityService.queryProcessingDataForPage(queryDTO);
        return getDataTable(list);
    }


    @ApiOperation(value = "过程加工数据-导出")
    @GetMapping("/exportProcessingData")
    @PreAuthorize("@ss.hasPermi('business:processingData:export')")
    public void exportProcessingData(HttpServletResponse response, QualityQueryDTO queryDTO) throws IOException {
        List<ProcessingDataVo> list = qualityService.queryProcessingDataForPage(queryDTO);
        // 使用 RuoYi 的 ExcelUtil 导出 Excel 文件
        new ExcelUtil<>(ProcessingDataVo.class).exportExcel(response, list, "过程加工数据-导出");
    }


    @ApiOperation(value = "产品合格率")
    @PreAuthorize("@ss.hasPermi('business:productQuality:query')")
    @GetMapping("/queryProductQuality")
    public TableDataInfo<ProductQuality> queryProductQuality(QualityQueryDTO queryDTO) {
        startPage();
        List<ProductQuality> list = qualityService.queryProductQuality(queryDTO);
        return getDataTable(list);
    }

    @ApiOperation(value = "处理产品合格接口")
    @PreAuthorize("@ss.hasPermi('business:productQuality:handle')")
    @PostMapping("/handleProductQuality")
    public AjaxResult handleProductQuality(@Validated @RequestBody QualityHandleDTO handleDTO) {
        return AjaxResult.success(qualityService.handleProductQuality(handleDTO));
    }

}
